package com.lg.system.user.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.lg.system.user.dao.UserRoleDao;
import com.lg.system.user.entity.UserRole;
import com.lg.system.user.service.UserRoleService;

/**
 * <p>
 * 用户与角色对应关系 服务实现类
 * </p>
 *
 * @author dl
 * @since 2018-03-23
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleDao, UserRole> implements UserRoleService {

	@Override
	public List<Long> selectRoleIdByUId(Long userId) {
		List<Long> roleIds=new ArrayList<>();
		Map<String, Object> param=new HashMap<>();
		param.put("user_id", userId);
		List<UserRole> userRoles=selectByMap(param);
		for(UserRole UserRole:userRoles){
			roleIds.add(UserRole.getRoleId());
		}
		return roleIds;
	}
	
	@Override
	public List<Long> selectUserIdByRId(Long roleId) {
		List<Long> userIds=new ArrayList<>();
		Map<String, Object> param=new HashMap<>();
		param.put("role_id", roleId);
		List<UserRole> userRoles=selectByMap(param);
		for(UserRole UserRole:userRoles){
			userIds.add(UserRole.getUserId());
		}
		return userIds;
	}

	@Override
	public boolean deleteByRoleId(Long roleId) {
		Map<String, Object> param=new HashMap<>();
		param.put("role_id", roleId);
		return deleteByMap(param);
	}

	@Override
	public boolean deleteByUserId(Long userId) {
		Map<String, Object> param=new HashMap<>();
		param.put("user_id", userId);
		return deleteByMap(param);
	}



}
